package com.study.pool;

import java.util.concurrent.*;
import java.util.concurrent.ArrayBlockingQueue;

public class ThreadPoolRejected
{
    public static void main(String[] args)
    {
        //自定义拒绝策略
        ExecutorService pool = new ThreadPoolExecutor(1, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(), new RejectedExecutionHandler()
        {
            public void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
            {
                System.out.println(r.toString() + "执行了拒绝策略");

            }
        });

        for (int i = 0; i < 10; i++)
        {
            pool.execute(new ThreadTask());
        }
    }
}
